package net.mcreator.makecustomitem.procedure;

import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.common.MinecraftForge;

import net.minecraft.world.World;
import net.minecraft.item.ItemStack;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.Entity;

import net.mcreator.makecustomitem.ElementsMakecustomitemMod;

import java.util.Map;

@ElementsMakecustomitemMod.ModElement.Tag
public class ProcedureAttributeGet extends ElementsMakecustomitemMod.ModElement {
	public ProcedureAttributeGet(ElementsMakecustomitemMod instance) {
		super(instance, 11);
	}

	public static void executeProcedure(Map<String, Object> dependencies) {
		if (dependencies.get("entity") == null) {
			System.err.println("Failed to load dependency entity for procedure AttributeGet!");
			return;
		}
		Entity entity = (Entity) dependencies.get("entity");
		if ((((((entity instanceof EntityPlayer) ? ((EntityPlayer) entity).inventory.armorInventory.get(0) : ItemStack.EMPTY).hasTagCompound()
				? ((entity instanceof EntityPlayer) ? ((EntityPlayer) entity).inventory.armorInventory.get(0) : ItemStack.EMPTY).getTagCompound()
						.getDouble("Defense")
				: -1) > 0) && ((entity.getEntityData().getBoolean("ArmorBlue1")) == (false)))) {
			entity.getEntityData().setDouble("ArmorNum1",
					(((entity instanceof EntityPlayer) ? ((EntityPlayer) entity).inventory.armorInventory.get(0) : ItemStack.EMPTY).hasTagCompound()
							? ((entity instanceof EntityPlayer) ? ((EntityPlayer) entity).inventory.armorInventory.get(0) : ItemStack.EMPTY)
									.getTagCompound().getDouble("Defense")
							: -1));
			entity.getEntityData().setDouble("Defense",
					((entity.getEntityData().getDouble("Defense")) + (entity.getEntityData().getDouble("ArmorNum1"))));
			entity.getEntityData().setBoolean("ArmorBlue1", (true));
		} else if ((((((entity instanceof EntityPlayer) ? ((EntityPlayer) entity).inventory.armorInventory.get(0) : ItemStack.EMPTY).hasTagCompound()
				? ((entity instanceof EntityPlayer) ? ((EntityPlayer) entity).inventory.armorInventory.get(0) : ItemStack.EMPTY).getTagCompound()
						.getDouble("Defense")
				: -1) <= 0) && ((entity.getEntityData().getBoolean("ArmorBlue1")) == (true)))) {
			entity.getEntityData().setDouble("Defense",
					((entity.getEntityData().getDouble("Defense")) - (entity.getEntityData().getDouble("ArmorNum1"))));
			entity.getEntityData().setBoolean("ArmorBlue1", (false));
		}
		if ((((((entity instanceof EntityPlayer) ? ((EntityPlayer) entity).inventory.armorInventory.get(1) : ItemStack.EMPTY).hasTagCompound()
				? ((entity instanceof EntityPlayer) ? ((EntityPlayer) entity).inventory.armorInventory.get(1) : ItemStack.EMPTY).getTagCompound()
						.getDouble("Defense")
				: -1) > 0) && ((entity.getEntityData().getBoolean("ArmorBlue2")) == (false)))) {
			entity.getEntityData().setDouble("ArmorNum2",
					(((entity instanceof EntityPlayer) ? ((EntityPlayer) entity).inventory.armorInventory.get(1) : ItemStack.EMPTY).hasTagCompound()
							? ((entity instanceof EntityPlayer) ? ((EntityPlayer) entity).inventory.armorInventory.get(1) : ItemStack.EMPTY)
									.getTagCompound().getDouble("Defense")
							: -1));
			entity.getEntityData().setDouble("Defense",
					((entity.getEntityData().getDouble("Defense")) + (entity.getEntityData().getDouble("ArmorNum2"))));
			entity.getEntityData().setBoolean("ArmorBlue2", (true));
		} else if ((((((entity instanceof EntityPlayer) ? ((EntityPlayer) entity).inventory.armorInventory.get(1) : ItemStack.EMPTY).hasTagCompound()
				? ((entity instanceof EntityPlayer) ? ((EntityPlayer) entity).inventory.armorInventory.get(1) : ItemStack.EMPTY).getTagCompound()
						.getDouble("Defense")
				: -1) <= 0) && ((entity.getEntityData().getBoolean("ArmorBlue2")) == (true)))) {
			entity.getEntityData().setDouble("Defense",
					((entity.getEntityData().getDouble("Defense")) - (entity.getEntityData().getDouble("ArmorNum2"))));
			entity.getEntityData().setBoolean("ArmorBlue2", (false));
		}
		if ((((((entity instanceof EntityPlayer) ? ((EntityPlayer) entity).inventory.armorInventory.get(2) : ItemStack.EMPTY).hasTagCompound()
				? ((entity instanceof EntityPlayer) ? ((EntityPlayer) entity).inventory.armorInventory.get(2) : ItemStack.EMPTY).getTagCompound()
						.getDouble("Defense")
				: -1) > 0) && ((entity.getEntityData().getBoolean("ArmorBlue3")) == (false)))) {
			entity.getEntityData().setDouble("ArmorNum3",
					(((entity instanceof EntityPlayer) ? ((EntityPlayer) entity).inventory.armorInventory.get(2) : ItemStack.EMPTY).hasTagCompound()
							? ((entity instanceof EntityPlayer) ? ((EntityPlayer) entity).inventory.armorInventory.get(2) : ItemStack.EMPTY)
									.getTagCompound().getDouble("Defense")
							: -1));
			entity.getEntityData().setDouble("Defense",
					((entity.getEntityData().getDouble("Defense")) + (entity.getEntityData().getDouble("ArmorNum3"))));
			entity.getEntityData().setBoolean("ArmorBlue3", (true));
		} else if ((((((entity instanceof EntityPlayer) ? ((EntityPlayer) entity).inventory.armorInventory.get(2) : ItemStack.EMPTY).hasTagCompound()
				? ((entity instanceof EntityPlayer) ? ((EntityPlayer) entity).inventory.armorInventory.get(2) : ItemStack.EMPTY).getTagCompound()
						.getDouble("Defense")
				: -1) <= 0) && ((entity.getEntityData().getBoolean("ArmorBlue3")) == (true)))) {
			entity.getEntityData().setDouble("Defense",
					((entity.getEntityData().getDouble("Defense")) - (entity.getEntityData().getDouble("ArmorNum3"))));
			entity.getEntityData().setBoolean("ArmorBlue3", (false));
		}
		if ((((((entity instanceof EntityPlayer) ? ((EntityPlayer) entity).inventory.armorInventory.get(3) : ItemStack.EMPTY).hasTagCompound()
				? ((entity instanceof EntityPlayer) ? ((EntityPlayer) entity).inventory.armorInventory.get(3) : ItemStack.EMPTY).getTagCompound()
						.getDouble("Defense")
				: -1) > 0) && ((entity.getEntityData().getBoolean("ArmorBlue4")) == (false)))) {
			entity.getEntityData().setDouble("ArmorNum4",
					(((entity instanceof EntityPlayer) ? ((EntityPlayer) entity).inventory.armorInventory.get(3) : ItemStack.EMPTY).hasTagCompound()
							? ((entity instanceof EntityPlayer) ? ((EntityPlayer) entity).inventory.armorInventory.get(3) : ItemStack.EMPTY)
									.getTagCompound().getDouble("Defense")
							: -1));
			entity.getEntityData().setDouble("Defense",
					((entity.getEntityData().getDouble("Defense")) + (entity.getEntityData().getDouble("ArmorNum4"))));
			entity.getEntityData().setBoolean("ArmorBlue4", (true));
		} else if ((((((entity instanceof EntityPlayer) ? ((EntityPlayer) entity).inventory.armorInventory.get(3) : ItemStack.EMPTY).hasTagCompound()
				? ((entity instanceof EntityPlayer) ? ((EntityPlayer) entity).inventory.armorInventory.get(3) : ItemStack.EMPTY).getTagCompound()
						.getDouble("Defense")
				: -1) <= 0) && ((entity.getEntityData().getBoolean("ArmorBlue4")) == (true)))) {
			entity.getEntityData().setDouble("Defense",
					((entity.getEntityData().getDouble("Defense")) - (entity.getEntityData().getDouble("ArmorNum4"))));
			entity.getEntityData().setBoolean("ArmorBlue4", (false));
		}
	}

	@SubscribeEvent
	public void onPlayerTick(TickEvent.PlayerTickEvent event) {
		if (event.phase == TickEvent.Phase.END) {
			Entity entity = event.player;
			World world = entity.world;
			int i = (int) entity.posX;
			int j = (int) entity.posY;
			int k = (int) entity.posZ;
			java.util.HashMap<String, Object> dependencies = new java.util.HashMap<>();
			dependencies.put("x", i);
			dependencies.put("y", j);
			dependencies.put("z", k);
			dependencies.put("world", world);
			dependencies.put("entity", entity);
			dependencies.put("event", event);
			this.executeProcedure(dependencies);
		}
	}

	@Override
	public void preInit(FMLPreInitializationEvent event) {
		MinecraftForge.EVENT_BUS.register(this);
	}
}
